package com.kfc.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Util {
	public static String JackMD(String method ,String passwd) {
		try {
			StringBuffer sBuffer = new StringBuffer();
			byte[] pass = MessageDigest.getInstance(method).digest(passwd.getBytes());
			for (int i = 0; i < pass.length; i++) {
				String temp  = Integer.toHexString(pass[i]);
				if (temp.length() < 2) {
					sBuffer.append("0" + temp);
				}else {
					sBuffer.append(temp.substring(temp.length()-2));
				}
			}
			return sBuffer.toString();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return null;
	}
	
	public static void main(String[] args) {
		System.out.println(Util.JackMD("md5", "123").length());
	}
}
